#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll n,x,mx,sa,sb,ans;
set<ll>s;
set<ll>::iterator it,itt;
int main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	cin>>n;
	while(n--){
		cin>>x,ans=mx=sa=sb=0;
		if((*s.lower_bound(x))==x)s.erase(x);
		else s.insert(x);
		for(it=s.begin(),itt=s.end(),itt--;itt!=s.begin();it++,itt--)sa+=(*itt),sb+=(*it),ans+=sa-max(sb,mx),mx=sa;
		cout<<ans<<"\n";
	}
	return 0;
}
